package com.rchat.pocmini.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by ljd on 2017/3/16.
 */

public class PocDbHelper extends SQLiteOpenHelper {

    private static final String TAG = "PocDbHelper";
    private static final String DB_NAME = "pocminidb";
    public static final int DB_VERSION = 1;
    private Context mContext;
    protected static final String CREATE_T_MESSAGE = "CREATE TABLE IF NOT EXISTS t_message(ID integer PRIMARY KEY AUTOINCREMENT,userid integer,msgId varchar(16),sid varchar(16),fromId varchar(16),fromName varchar(32),fromPhotoId varchar(16),type integer,typeSub integer,recordType integer,dtTime varchar(32),dtDate varchar(32),state integer,contentText TEXT,contentRes TEXT,contentResLen integer)";

    public static PocDbHelper get(Context context) {
        return BeanManager.get().getBean(PocDbHelper.class, context);
    }


    public static class Creator implements BeanManager.Creator<PocDbHelper> {
        @Override
        public boolean isSingleton() {
            return true;
        }

        @Override
        public PocDbHelper create(Context context) {
            return new PocDbHelper(context,
                    DB_NAME,
                    null,
                    DB_VERSION);
        }
    }

    private PocDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                        int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
//        db.execSQL(PocDbConstants.CREATE_T_CHANNEL);
        db.execSQL(CREATE_T_MESSAGE);
//        db.execSQL(PocDbConstants.CREATE_T_REPORT);
//        db.execSQL(PocDbConstants.CREATE_T_SESSION);
//        db.execSQL(PocDbConstants.CREATE_T_SESSION_MEMBER);
//        db.execSQL(PocDbConstants.CREATE_T_BROADCAST);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//        switch (newVersion) {
//            case 2:
//                updateSQLiteDatabaseWhenVersion2(db);
////		case 3: db.execSQL(DB_CREATE_MODULE_DATA_SQL);
//            default:
//                break;
//        }
    }

//    private void updateSQLiteDatabaseWhenVersion2(SQLiteDatabase db) {
////        // 创建广播信息表
////        db.execSQL(PocDbConstants.CREATE_T_BROADCAST);
////        // 给t_channel表添加字段
////        db.execSQL("ALTER TABLE " + PocDbConstants.db_channel + " ADD COLUMN "
////                + PocDbConstants.t_channel.unreadCount + " integer DEFAULT 0");
//        // 给t_message表添加字段
//        db.execSQL("ALTER TABLE " + "t_message" + " ADD COLUMN "
//                + "recordType" + " integer DEFAULT 0");
//    }
}

